package com.caption.api.utils;

import org.apache.logging.log4j.ThreadContext;
import org.springframework.core.task.TaskDecorator;

/**
 * 异步线程TaskDecorator
 *
 *
 */
public class ThreadContextTaskDecorator implements TaskDecorator {

	@Override
	public Runnable decorate(Runnable runnable) {
		String txnId = ThreadContext.peek();
		return () ->{
			try {
				ThreadContext.push(txnId);
				runnable.run();
			} finally {
				ThreadContext.pop();
			}
		};
	}

}
